package com.leapp.sk.viewdelegate.adapter.im

import android.content.Context
import android.view.View
import android.widget.TextView
import cc.vv.lkbasecomponent.util.LKDateTimeUtil
import cc.vv.lkimcomponent.lkim.bean.LKIMMessage
import cc.vv.lkimcomponent.lkim.bean.body.LKIMTxtBody
import com.example.mvp.delegate.BaseAdapterDelegate
import com.leapp.sk.R
import com.leapp.sk.util.SKTimeUtil

/**
 * 其它通知类型消息
 * @author  chaohaipeng  on 2018/7/24.
 */
class OtherNoticeMsgAdapterDelegate : BaseAdapterDelegate() {
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.sk_chat_notice_message_item

    }

    /**
     * 设置收到消息View
     */
    fun setRecerveView(context: Context, lkimMessage: LKIMMessage, timeInterval:Int, position: Int){
        val tv_scnmi_time=getView<TextView>(R.id.tv_scnmi_time)
        val tv_scnmi_content=getView<TextView>(R.id.tv_scnmi_content)
        tv_scnmi_time.text=LKDateTimeUtil.formatDateTime(lkimMessage.msgTime,"")
        isShowTime(tv_scnmi_time, timeInterval, lkimMessage.msgTime, position)
        var lkImBody:LKIMTxtBody?=null
        try {
            lkImBody= lkimMessage.lkIMBody as LKIMTxtBody
        }catch (e:Exception){
            lkImBody=null
        }
        tv_scnmi_content.text=lkImBody?.message
    }



    /**
     * 间隔时间处理
     *
     * @param tv_time
     * @param timeInterval
     * @param time
     */
    private fun isShowTime(tv_time: TextView, timeInterval: Int, time: Long, position: Int) {
        if (timeInterval >= 5) {
            val dayOrHours = SKTimeUtil.getDayOrHours(time)
            tv_time.text=dayOrHours
            tv_time.visibility = View.VISIBLE
        } else {
            if (position == 0) {
                val dayOrHours = SKTimeUtil.getDayOrHours(time)
                tv_time.text=dayOrHours
                tv_time.visibility = View.VISIBLE
            } else {
                tv_time.visibility = View.GONE
            }

        }
    }

}